import { RootState } from '../types'
import { allProductsSlice } from './slices/allProductsSlice'
import { userSlice } from './slices/userSlice'
import { catalogSlice } from './slices/catalogSlice'
import { searchSlice } from './slices/searchSlice'
import { productSlice } from './slices/productSlice'
import { alertSlice } from './slices/alertSlice'
import { loadingSlice } from './slices/loadingSlice'

export const selectAccessToken = (state: RootState) =>
	state[userSlice.name].token
export const selectUser = (state: RootState) => state[userSlice.name].data

export const selectAllProductsPending = (state: RootState) =>
	state[allProductsSlice.name].loading
export const selectAllProducts = (state: RootState) =>
	state[allProductsSlice.name].data

export const selectCatalogPending = (state: RootState) =>
	state[catalogSlice.name].loading
export const selectCatalog = (state: RootState) => state[catalogSlice.name].data
export const selectCatalogPagination = (state: RootState) =>
	state[catalogSlice.name].pagination
export const selectCatalogQuantity = (state: RootState) =>
	state[catalogSlice.name].quantity

export const selectPage = (state: RootState) =>
	state[catalogSlice.name].pagination.selectedPage

export const selectSearch = (state: RootState) => state[searchSlice.name].search

export const selectProduct = (state: RootState) => state[productSlice.name].data
export const selectProductReviews = (state: RootState) =>
	state[productSlice.name].data?.reviews

export const selectAlertType = (state: RootState) => state[alertSlice.name].type
export const selectAlertIsOpen = (state: RootState) =>
	state[alertSlice.name].isOpen
export const selectAlertText = (state: RootState) => state[alertSlice.name].text

export const selectIsLoading = (state: RootState) =>
	state[loadingSlice.name].isLoading
